﻿using AccustomeAttributedll;
using AixCommInfo;
using ISaveReaddll;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static LanCustomControldll.Unit_Aix.UC_SimpleCalcMode;

namespace FinalTestMachine.Motion.Aixs.Light
{

    class Aix_LightBaseBase : AixCreateBase
    {

        public Aix_LightBaseBase(ApplicationSettingsBase applicationSettingsBase) : base(applicationSettingsBase)
        {
            LightList.Add(this);
            WaitPos = new SingleAixPosAndSpeedMsgAndIMov(() => this);
        }

        public static List<Aix_LightBaseBase> LightList = new List<Aix_LightBaseBase>();

        #region 覆写方法区

        #endregion

        #region 功能实例


        [SaveRemark]
        [TextBoxRemark("等待位")]
        [ButtonRemark("等待位")]
        /// <summary>
        /// 等待位
        /// </summary>
        public readonly SingleAixPosAndSpeedMsgAndIMov WaitPos;



        //[SaveRemark]
        //[TextBoxParamRemark("工作位")]
        //[ButtonRemark("工作位")]
        ///// <summary>
        ///// 工作位
        ///// </summary>
        //public readonly SingleAixPosAndSpeedAndMovHelper WorkPos = new SingleAixPosAndSpeedAndMovHelper(() => CurAix);

        #endregion

        #region 方法操作

        /// <summary>
        /// 自动完成回原和去等待位
        /// </summary>
        public static void Fun_HomeAll()
        {
            List<Task> tasks = new List<Task>();

            foreach (var item in LightList)
            {

                tasks.Add(Task.Run(() =>
                {
                    if (Funs.FunLightPipeSettings.Cur.CheckCurrentLighgPiPeCanUse(item.Name))
                    {
                        item.Home();
                        item.WaitPos.Mov(true);
                    }

                }));
            }

            Task.WaitAll(tasks.ToArray());
        }

        public static void Fun_MovWaitAll()
        {
            foreach (var item in LightList)
            {
                if (!Funs.FunLightPipeSettings.Cur.CheckCurrentLighgPiPeCanUse(item.Name))
                    continue;

                item.WaitPos.Mov(false);
            }
            foreach (var item in LightList)
            {
                if (!Funs.FunLightPipeSettings.Cur.CheckCurrentLighgPiPeCanUse(item.Name))
                    continue;

                item.WaitDone();
            }
        }

        public static void Fun_StopAll()
        {
            foreach (var item in LightList)
            {
                item.StopSlowDown();
            }
        }

        #endregion

    }
    class Aix_LightBase1 : Aix_LightBaseBase
    {

        public Aix_LightBase1(ApplicationSettingsBase applicationSettingsBase) : base(applicationSettingsBase)
        {
           
        }

        [SaveRemark]
        public readonly LightCalculaorParam CalculaorParam = new LightCalculaorParam();

       

    }

    class Aix_LightBase2 : Aix_LightBaseBase
    {

        public Aix_LightBase2(ApplicationSettingsBase applicationSettingsBase) : base(applicationSettingsBase)
        {
           
        }

        [SaveRemark]
        public readonly View.AixCalcView.UC_SimpleCalcMode.LightCalculaorParam CalculaorParam = new View.AixCalcView.UC_SimpleCalcMode.LightCalculaorParam();


       
    }
}
